const fs=require('fs');
const path=require('path');
const http=require('http');

http.createServer((req,res)=>{
    // console.log(req.url);
    var urlStr=req.url;
    var filePath=path.join(__dirname,'/text.html');
    var imgPath=path.join(__dirname,'/icon.png');
    // 当请求的资源路径是/时，响应网页文件到浏览器
    if(urlStr=='/'){
        var fileContent=fs.readFileSync(filePath);
        res.writeHead(200,{'Content-Type':'text/html;charset=utf8'});
        res.write(fileContent);
        res.end();
    }
    else if(urlStr=='/icon.png'){
        var imgContent=fs.readFileSync(imgPath);
        res.writeHead(200,{'Content-Type':'image/png'});
        res.write(imgContent);
        res.end();
    }
  
}).listen(8082);

console.log('server is listening 8082');

